﻿using System.Collections.Concurrent;

namespace DataManageSystem.Services
{
    public class HeartbeatService
    {
        private readonly ConcurrentDictionary<string, DateTime> _heartbeatMap = new();

        public void Update(string systemId)
        {
            _heartbeatMap[systemId] = DateTime.UtcNow;
        }

        public List<(string SystemId, DateTime LastSeen, bool IsOnline)> GetStatus(TimeSpan timeout)
        {
            var now = DateTime.UtcNow;
            return _heartbeatMap.Select(entry => (
                entry.Key,
                entry.Value,
                now - entry.Value < timeout
            )).ToList();
        }
    }
}
